package net.huashitong.Indicators.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.Indicators.dao.OneIndexDao;
import net.huashitong.Indicators.entity.OneIndex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.Table;
import java.util.List;

@Service
public class OneIndexService extends StringPKService<OneIndex> {

    @Autowired
    private OneIndexDao dao;
    @Autowired
    private SysTableService tabservice;

    @Override
    protected BaseDao<OneIndex, String> getDao() {
        return dao;
    }

    @Override
    protected void beforeSave(OneIndex obj) {
        //super.beforeSave(obj);
        obj.setSysId(tabservice.updateMaxSysId("AB01", null));
    }

    public OneIndex queryByCodeId(String code) {
        return dao.queryByCodeId(code);
    }


    /**
     * app首页子节点
     */
    public List<OneIndex> getChileCate(String parentCode, String codeNode) {
        return dao.getChileCatalogue(parentCode, codeNode);
    }


    /**
     * 所有二级指标
     *
     * @return
     */
    public List<OneIndex> getTwoNode(String codetype, String codeNode, String areaType) {
        return dao.getTwoNode(codetype, codeNode, areaType);
    }

    /**
     * 从临时表中获取指标
     *
     * @param
     * @return
     */
    public List<OneIndex> getIndexFromTemp() {
        return dao.getIndexFromTemp();
    }

    /**
     * 根据父节点ID拿到子节点
     */
    public List<OneIndex> getChileNode(String pareentCode, String codetype, String areaType) {

        return dao.getChileNode(pareentCode, codetype, areaType);
    }


   /* public List<OneIndex> getTest()
    {
        return dao.getIndextest();
    }*/

    /**
     * 删除指标
     */
    public void deleteOneIndex(String codeType, String areaType) {
        dao.deleteOneIndex(codeType, areaType);
    }

    public void deleteIndexByCodeNode(String codeType, String areaType, String codeNode) {
        dao.deleteIndexByCodeNode(codeType, areaType, codeNode);
    }

    public List<OneIndex> getAllIndexs(String codeType, String areaType) {
        return dao.getAllIndex(codeType, areaType);
    }


    public List<OneIndex> getViews(String areatype, String codenode, String parentCode) {
        return dao.getViewBy(areatype, codenode, parentCode);
    }

    public List<OneIndex> queryOneIndexByAreaTypeAndCodeType(String areaType, String codeType) {
        return dao.queryOneIndexByAreaTypeAndCodeType(areaType, codeType);
    }


    /**
     * @param code_id
     * @param codeType
     * @param areaType
     * @return
     */
    public List<OneIndex> getNameById(String code_id, String codeType, String areaType, String datetime) {
        return dao.getIndexNameById(code_id, codeType, areaType, datetime);
    }

    public List<OneIndex> getCodeNode(String lastNode, String currentNode, String codeType, String areaType) {
        return dao.getNodeCodeId(lastNode, currentNode, codeType, areaType);
    }


}
